import 'package:dmz/base/pageWidget/base_stateful_widget.dart';
import 'package:dmz/business/home/controller/home_main_controller.dart';
import 'package:dmz/business/home/widgets/home_moto.dart';
import 'package:dmz/business/home/widgets/home_no_moto.dart';
import 'package:dmz/business/home/widgets/home_widgets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:visibility_detector/visibility_detector.dart';

class HomePage extends BaseStatefulWidget<HomePageController> {
  const HomePage({super.key});

  @override
  bool showTitleBar() => false;

  @override
  bool showTransparent() => true;

  @override
  Widget buildContent(BuildContext context) {
    return Stack(children: [
      VisibilityDetector(
          key: const Key('homeMian'),
          onVisibilityChanged: (visibilityInfo) =>
              controller.didVehicleRefresh(visibilityInfo.visibleFraction == 1),
          child: PageView.builder(
              physics: const NeverScrollableScrollPhysics(),
              controller: controller.pageController,
              itemCount: controller.motoList.length,
              onPageChanged: controller.changeMoto,
              itemBuilder: (BuildContext context, int index) {
                return controller.motoList[index].sn_code == null
                    ? HomeNoMotoWidget(
                        clickAction: controller.clickActionWithOnMoto) //无车辆
                    : GetBuilder<HomePageController>(
                        id: 'Moto$index',
                        builder: (controller) {
                          return HomeMotoWidget(
                              model: controller.motoList[index],
                              clickAction: controller.clickActionWithMoto);
                        }); //有车辆
              }).marginOnly(top: getTop(context), bottom: getBottom(context))),
      if (controller.motoList.length > 1)
        HomeWidgets.changeIcons(controller.clickActionWithMoto), //切换车辆

      if (controller.haveNewShare)
        HomeWidgets.shareWidget(controller.turnShareList)
    ]).addGestureDetector(controller.bottomAction);
  }
}
